#ifndef WATCHLIST_HPP
#define WATCHLIST_HPP

#include <QDockWidget>
#include <QMap>
#include <QMapIterator>
#include <QTableWidgetItem>
#include <QList>

#include "datamemoryorganisation.hpp"
#include "register.hpp"

namespace Ui {
    class WatchList;
}

/**
* @brief Watchlist showing available variables and their values
* @details The Watchlist will allow the user to see all available variables in the current program
* together with their current values. \n
* The variables are added when the Decoder parses the LST file and finds EQU statements. \n
* The current values are updated automatically when the watched Registers change
*
* @class WatchList watchlist.hpp "watchlist.hpp"
*/
class WatchList : public QDockWidget {
    Q_OBJECT

public:
    /**
    * @brief Watchlist Constructor
    *
    * @fn WatchList(QWidget *parent = 0)
    * @param parent
    */
    WatchList(QWidget *parent = 0);

    /**
    * @brief Watchlist Destructor
    *
    * @fn ~WatchList
    */
    ~WatchList();

    /**
    * @brief Will reset the complete Watchlist
    *
    * @fn void reset()
    */
    void reset();

    /**
    * @brief Update the Table with the new values
    *
    * @fn void updateView()
    */
    void updateView();

protected:
    /**
    * @brief Act on language change event
    *
    * @fn void changeEvent(QEvent *e)
    * @param e
    */
    void changeEvent(QEvent *e);

private:
    Ui::WatchList *ui;
    QMap<int, QString> variableValue1Map;
    QMap<int, QString> variableValue2Map;
    QMap<int, QString> variableNameMap;
    QList<QTableWidgetItem*> itemList;

public slots:
    /**
    * @brief Slot called when Decoder finds a new variable (EQU)
    *
    * @fn void onVariableAdded(QString name, QString address)
    * @param name
    * @param address
    */
    void onVariableAdded(QString name, QString address);

    /**
    * @brief Slot called whenever a Register changes
    *
    * @fn void onVariableChanged(Register *reg)
    * @param reg
    */
    void onVariableChanged(Register *reg);

signals:
    /**
    * @brief Signal emitted when a variable has changed to adjust the corresponding tooltip accordingly
    *
    * @fn void variableTooltipChanged(QString var, QString val)
    * @param var
    * @param val
    */
    void variableTooltipChanged(QString var, QString val);
};

#endif // WATCHLIST_HPP
